﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Repetition.Utilities
{
    public class Template
    {
        public static string InstantiateFileTemplate(string filename, IDictionary<string, string> replacements)
        {
            // Read template from file
            FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(file);
            
            string template = reader.ReadToEnd();
            
            reader.Close();

            return InstantiateStringTemplate(template, replacements);
        }

        public static string InstantiateStringTemplate(string template, IDictionary<string, string> replacements)
        {
            foreach (var pair in replacements)
                template = template.Replace(pair.Key, pair.Value);

            return template;
        }
    }
}
